package com.xxgc.eow.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.xxgc.eow.entity.Comment;
import com.xxgc.eow.entity.CommentSecondary;
import com.xxgc.eow.entity.Secondaycomment;
import com.xxgc.eow.mapper.CommentMapper;
import com.xxgc.eow.service.ICommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.*;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author Mr.Abel
 * @since 2023-05-22
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {

    @Resource
    private CommentMapper commentMapper;

    @Override
    public List<Comment> selectByArticleId(int article) {
        return commentMapper.selectArticleId(article);
    }

    @Override
    public int delCommentById(int commentId) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        return commentMapper.delComment(commentId,localDateTime);
    }

    @Override
    public List<Secondaycomment> selectSecondComment(int commentId) {
        return commentMapper.selectSecondComment(commentId);
    }

    @Override
    public CommentSecondary selectById(int commentId) {
        return commentMapper.selectByCommentId(commentId);
    }

    @Override
    public List<Comment> selectArticleByUserId(int userId) {
        return commentMapper.selectArticleByUserId(userId);
    }

    @Override
    public List<CommentSecondary> selectAll() {
        return commentMapper.selectAll();
    }
}
